package com.iman.sumer.service.impl.teamgroup;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.iman.common.hibernate.TemplateQLService;
import com.iman.common.support.Page;
import com.iman.sumer.service.teamgroup.GroupShareService;
import com.iman.sumer.vo.teamgroup.GroupShareVo;

@Service
public class GroupShareServiceImpl implements GroupShareService {
	@Inject
    private TemplateQLService templateQLService;

	@Override
	public Page<GroupShareVo> getShareList(Map<String, Object> params) {
		Integer ps = Integer.valueOf(params.get("ps").toString());
		Integer pn = Integer.valueOf(params.get("pn").toString());
		params.put("startNo", ps*pn);
 		Page<GroupShareVo> vos = templateQLService.findByPagedSQLBeanQuery(
				"group_share_list", params, Page.getStartOfPage(pn, ps), ps,
				GroupShareVo.class);
		return vos;
	}

	@Override
	public List<Map> getGroupShareList(Map<String, Object> params) {
		List<Map> vos = templateQLService.findBySQLMapQuery("group_share_list", params);
		return vos;
	}
	
	@Override
	public List<Map> getGroupShareListTop3(Map<String, Object> params) {
		List<Map> vos = templateQLService.findBySQLMapQuery("group_share_list_top3", params);
		return vos;
	}

	@Override
	public GroupShareVo getGroupShareByID(long shareId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void addGroupShare(Map params) {
		templateQLService.executeSQLUpdate("add_group_share", params);
	}

	@Override
	public int updateGroupShare(GroupShareVo gsv) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void addSharedFile(Map params) {
		templateQLService.executeSQLUpdate("add_shared_file", params);
	}

	@Override
	public Map addSharedResource(Map params) {
		templateQLService.executeSQLUpdate("add_shared_resource", params);
		List<Map> vos = templateQLService.findBySQLMapQuery("last_share_resource_id", params);
		if(vos.size()>0){
			return vos.get(0);
		}else{
			return null;
		}
	}

	@Override
	public void updateSharedResource(Map params) {
		templateQLService.executeSQLUpdate("update_shared_resource", params);
	}

	@Override
	public void delGroupShare(Map params) {
		templateQLService.executeSQLUpdate("delete_group_share", params);
	}
	
	

}
